package myjava.initializers;

public class Root1 {

   public static void main(String[] args) {

      new Foo();
   }
}

class Foo {

   // @@@ instance init : runs averytime an instance is created
   /*
       - executed in the order they appear
       - executed immediately after super() returns
       - they should be used to exec code that otherwise would be duplicated in each contructor */
   {
      // stuff executed only once at instantiation time
      System.out.println("instantiation time! # 1");
   }

   {
      // stuff executed only once at instantiation time
      System.out.println("instantiation time! # 2");
   }


   // @@@ static init : runs only when the class is loaded
   static {
      System.out.println("class loading time! # 1");
   }

   static {
      System.out.println("class loading time! # 2");
   }

   Foo() {
      this(1);
      System.out.println("empty constr");
   }

   Foo(int n) {
      System.out.println("1 arg contr");
   }
}

/* RESULTS

 * class loading time! # 1
 * class loading time! # 2
 * super (invisible)
 * instantiation time! # 1
 * instantiation time! # 2
 * 1 arg contr
 * empty contr */



















